﻿@using Newbe.BookmarkManager.Services
@using Microsoft.Extensions.Logging
@using Microsoft.Extensions.Options
@using Newbe.BookmarkManager.Services.Configuration
@if (DevOptions.Value.Enabled)
{
    <Space>
        <SpaceItem>
            <Button OnClick="ClickResetPrivacyAgreementStatusAsync">Reset Privacy Agreement Status</Button>
        </SpaceItem>
        <SpaceItem>
            <Button OnClick="ClickResetWelcomeStatusAsync">Reset Welcome Status</Button>
        </SpaceItem>
    </Space>
}

@code {

    [Inject]
    public IOptions<DevOptions> DevOptions { get; set; }

    [Inject]
    public ILogger<DevButtons> Logger { get; set; }

    [Inject]
    public IUserOptionsService UserOptionsService { get; set; }

    [Inject]
    public IIndexedDbRepo<AfMetadata, string> AfMetadataRepo { get; set; }

    private async Task ClickResetPrivacyAgreementStatusAsync(MouseEventArgs obj)
    {
        var userOptions = await UserOptionsService.GetOptionsAsync();
        userOptions.AcceptPrivacyAgreementVersion = string.Empty;
        await UserOptionsService.SaveAsync(userOptions);
        Logger.LogInformation("Reset Privacy Agreement Status success");
    }

    private async Task ClickResetWelcomeStatusAsync(MouseEventArgs obj)
    {
        var afMetadata = await AfMetadataRepo.GetSingleOneAsync();
        afMetadata ??= new AfMetadata();
        afMetadata.WelcomeShown = false;
        await AfMetadataRepo.UpsertAsync(afMetadata);
        Logger.LogInformation("Reset Privacy Agreement Status success");
    }

}